﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;

namespace Microsoft.ProductivityHub.SilverlightBookshelf
{

    public class ContentItem : IComparable<ContentItem>
    {
        private string _title = "Default Title";
        private string _docUrl = "";
        private string _abstract = "Default Abstract";
        private string _iconUrl = "";

        private BitmapImage _icon = null;
        private double _ratingValue = 0.5;
        private string _docId = "";
        private string _product = "DefaultProduct";
        private string _difficulty = "DefaultDifficulty";
        private int _numberOfRatings = 0;

        public int CompareTo(ContentItem item)
        {
            return this.Title.CompareTo(item.Title);
        }

        public string DocUrl
        {
            get { return _docUrl; }
            set { _docUrl = value; }
        }

        public string IconUrl
        {
            get { return _iconUrl; }
            set 
            { 
                _iconUrl = value;
            }
        }

        public BitmapImage Icon
        {
            get
            {
                if (_icon == null)
                {
                    _icon = new BitmapImage(new Uri(this.IconUrl, UriKind.Relative));

                }
                return _icon;
            }

        
        }
        /// <summary>
        /// To bind to the Silverlight Input:Rating control, we're using continuous mode, must provide a value 0 to 1
        /// Take a 3.5 and divide by 5 (number of rating items(stars) available
        /// </summary>
        public double RatingValue
        {
            get { return _ratingValue; }
            set 
            {
                if (value > 1.0)
                {
                    _ratingValue = (value / 5);
                }
                else
                {
                    _ratingValue = value;

                }
            }
        }

        public string DocId
        {
            get { return _docId; }
            set { _docId = value; }
        }

        public string Product
        {
            get { return _product; }
            set { _product = value; }
        }

        public string Difficulty
        {
            get { return _difficulty; }
            set { _difficulty = value; }
        }

        public int NumberOfRatings
        {
            get { return _numberOfRatings; }
            set { _numberOfRatings = value; }
        }

        public string NumberOfRatingsString
        {
            get 
            {
                if (_numberOfRatings == 1)
                {
                    return "(" + _numberOfRatings + " rating)"; 

                }
                else
                {
                    return "(" + _numberOfRatings + " ratings)"; 
                }
            }
        }

        public string Abstract
        {
            get { return _abstract; }
            set { _abstract = value; }
        }

        public string Title
        {
            get { return _title; }
            set { _title = value; }
        }

        public ContentItem()
        {
        }

        public ContentItem(string title, string docAbstract)
        {
            this.Title = title;
            this.Abstract = docAbstract;
        }
    }
}
